package public

import (
	"MembershipRegist/db"
	"MembershipRegist/models"
)

// 需要测试
func (c *Controller) ActivityComments() {
	activityID, err := c.GetInt("activity_id")
	if err != nil {
		c.ResponseFailed(201, "activity_id 不合法")
		return
	}

	var comments []models.OrganizationActivityComment
	offset := c.GetString("offset")
	limit := c.GetString("limit")
	if limit == "" || limit == "0" {
		db.DB.Where("organization_activity_id = ?", activityID).
			Preload("User").
			Preload("OrganizationActivity").
			Preload("OrganizationAdmin").Find(&comments)
	} else {
		db.DB.Where("organization_activity_id = ?", activityID).
			Preload("User").
			Preload("OrganizationActivity").
			Preload("OrganizationAdmin").
			Limit(limit).Offset(offset).Find(&comments)
	}

	var total int
	db.DB.Model(&models.OrganizationActivityComment{}).Count(&total)
	result := make(map[string]interface{})
	result["status"] = 200
	result["message"] = "success"
	result["total"] = total
	result["comments"] = comments
	c.Data["json"] = result
	c.ServeJSON()

}
